import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);
const originalPush = Router.prototype.push;
//修改原型对象中的push方法解决点击相同的菜单页报错重复点击
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
export default new Router({
  mode: "hash",
  /**
   * router的配置：
   * 为了方便显示面包线的内容，需有层级关系，（目前最多有三层）
   * 所有的页面都在首页下
   *
   * 如有第三级页面，他的父级（也就是二级）也需要有path、name和路径
   * path和name可以随便取名（不冲突就可以），路径为page文件夹下的system.vue
   *
   * 不需要显示到面包线内的页面，需写到首页的同级，例如登录页
   */
  routes: [
    {
      path: "/",
      name: "main",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "home",
      component: () =>
        import(/* webpackChunkName: "home" */ "./components/common/Home.vue"),
      meta: { title: "首页" },
      redirect: "/dashboard",
      children: [
        {
          path: "/dashboard",
          name: "dashboard",
          component: () =>
            import(
              /* webpackChunkName: "dashboard" */ "./components/page/Dashboard.vue"
            ),
          meta: { title: "系统首页" },
        },
        {
          path: "/system",
          name: "system",
          meta: {title: "系统管理"},
          component: () =>
            import(
              /* webpackChunkName: "system" */ "./components/page/system.vue"
              ),
          children: [
            {
              path: "BuMenRenYuanGuanLi",
              name: "BuMenRenYuanGuanLi",
              component: () =>
                import(
                  /* webpackChunkName: "BuMenRenYuanGuanLi" */ "./components/page/XiTongGuanLi/BuMengRenYuanGuanLi/BuMenRenYuanGuanLi"
                  ),
              meta: {title: "部门人员管理"},
            },
            {
              path: "bumenrenyuanguanli/bianjibumen/:pk",
              name: "bianjibumen",
              meta: {title: "部门编辑"},
              // route level code-splitting
              // this generates a separate chunk (about.[hash].js) for this route
              // which is lazy-loaded when the route is visited.
              component: () => import(/* webpackChunkName: "index" */ "./components/page/XiTongGuanLi/BuMengRenYuanGuanLi/BianJiBuMen")
            }, {
              path: "bumenrenyuanguanli/xinzengbumen",
              name: "xinzengbumen",
              meta: {title: "部门新增"},
              // route level code-splitting
              // this generates a separate chunk (about.[hash].js) for this route
              // which is lazy-loaded when the route is visited.
              component: () => import(/* webpackChunkName: "index" */ "./components/page/XiTongGuanLi/BuMengRenYuanGuanLi/XinZengBuMen")
            },
            {
              path: "/renyuanguanli/:pk",
              name: "renyuanguanli",
              component: () =>
                import(
                  /* webpackChunkName: "RenYuanGuanLi" */ "./components/page/XiTongGuanLi/BuMengRenYuanGuanLi/RenYuanGuanLi/RenYuanGuanLi.vue"
                  ),
              meta: {title: "部门人员管理"},
            },
            {
              path: "JueSeGuanLi",
              name: "JueSeGuanLi",
              component: () =>
                import(
                  /* webpackChunkName: "JueSeGuanLi" */ "./components/page/XiTongGuanLi/JueSeGuanLi.vue"
                  ),
              meta: {title: "角色管理"},
            },
            {
              path: "JiBenXinXiGuanLi",
              name: "JiBenXinXiGuanLi",
              component: () =>
                import(
                  /* webpackChunkName: "JiBenXinXiGuanLi" */ "./components/page/XiTongGuanLi/JiBenXinXiGuanLi.vue"
                  ),
              meta: {title: "基本信息管理"},
            },
          ],
        },
      ],
    },
    {
      path: "/registerSuccess",
      name: "registerSuccess",
      component: () =>
        import(
          /* webpackChunkName: "registerSuccess" */ "./components/page/RegisterSuccess.vue"
        ),
      meta: { title: "申请注册成功" },
    },
    {
      path: "/login",
      component: () =>
        import(/* webpackChunkName: "login" */ "./components/page/Login.vue"),
      meta: { title: "登录" },
    },
    {
      path: "/404",
      component: () =>
        import(/* webpackChunkName: "404" */ "./components/page/404.vue"),
      meta: { title: "404" },
    },
    {
      path: "*",
      redirect: "/404",
    },
  ],
});
